package com.labofjet.aspect;

import java.util.UUID;

import org.aspectj.lang.ProceedingJoinPoint;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * 基础日志记录
 * @author jyzjyz12@163.com
 *
 */
public abstract class BaseLogAspect {

	private static final Logger LOGGER = LoggerFactory.getLogger(BaseLogAspect.class);

	protected Object doLog(ProceedingJoinPoint pjp, String type) throws Throwable {// NOSONAR
		UUID uuid = UUID.randomUUID();
		String signature = pjp.getSignature().toString();
		LOGGER.info("识别号[sequenceid:{}]: 调用{}方法: {}", uuid, type, signature);
		LOGGER.debug("识别号[sequenceid:{}]: 参数为 {}", uuid, pjp.getArgs());
		try {
			long start = System.currentTimeMillis();
			Object result = pjp.proceed();
			LOGGER.info("识别号[sequenceid:{}]: 调用{}方法: {} 成功! 返回 {}", uuid, type, signature, result);
			LOGGER.info("识别号[sequenceid:{}]: 调用消耗时间为[timecost:{}]", uuid, System.currentTimeMillis() - start);
			return result;
		}
		catch (Exception e) {
			LOGGER.error("识别号[sequenceid:{}]: 调用{}方法: {} 失败!", uuid, type, signature);
			LOGGER.error("识别号[sequenceid:{}]: 异常时输入为 {}", uuid, pjp.getArgs());
			LOGGER.error("识别号[sequenceid:{}]: 异常为: ", uuid, e);
			throw e;
		}
	}

}
